var lastMenuObject = null;
$(document).ready(function(){
    
    
    $(".fakeLink").live("click", function (e){
        e.preventDefault();
    });
    
    $("#delivery-no").live("click",function (event){
        if($(this).attr("checked")){
            $("#d_name").attr('disabled', true);
            $("#d_surname").attr('disabled', true);
            $("#d_company").attr('disabled', true);
            $("#d_street").attr('disabled', true);
            $("#d_town").attr('disabled', true);
            $("#d_zip").attr('disabled', true);
            $("#d_country").attr('disabled', true);
        }else{
            $("#d_name").removeAttr('disabled');             
            $("#d_surname").removeAttr('disabled');
            $("#d_company").removeAttr('disabled');
            $("#d_street").removeAttr('disabled');
            $("#d_town").removeAttr('disabled');
            $("#d_zip").removeAttr('disabled');
            $("#d_country").removeAttr('disabled');
        }
        
    });
    //kosikOverview
    $("#prejitKPokladneDiv").live("click",function(event){
        location.hash = "prejitKPokladne";
    });
    //prejit k platbe
    $("#prejitKPlatbe").live("click",function(event){
        if (pridatZbozi()){
            location.hash = "k";
        }        
    });
    //odeslani nejakeho formular
    $(".sendFormButton").live("click",function(event){
        location.hash = "sendForm:"+$(this).attr("data-formId");
    });
    //minimenu position
    var visibleEditElement = null;    
    $(window).scroll(function () { 
        $("div.minimenuCatPosition").stop(true,true).hide();    
    });
    
    function correctMinimenuPosition(){        
        newY = visibleEditElement.offset().top-$(window).scrollTop()*2-visibleEditElement.parent().height();
        newX = visibleEditElement.offset().left-$(window).scrollLeft()+visibleEditElement.parent().width();
        visibleEditElement.css({
            left: newX,
            top: newY
        })
    }
    
    
    var itemDetailIdCatche = null;
    //kosik fademenu click
    $("div.goToDetail").live("click",function(event){
        var itemId = $(this).attr("detailItemId");
        var barva = $(this).attr("barva");
        var velikost = $(this).attr("velikost");
        $("div.itemListDiv").html('<img src="templates/eshop/imgs/LoadingIcon-Gray.gif" />').load("eshopScript/Ajax.php?detailItemId="+itemId,function(){
            var image = $("img[barva='"+barva+"']");
            $("img.detailBarva").addClass("opacityHalf");
            image.removeClass("opacityHalf");                       
            $("div.detail").attr("barva",barva);                        
            var cisId = image.attr("barva");
            getBarvaDetailImg(cisId);
            var velikostText = $("div.detailVelikost[velikost='"+velikost+"']");
            $("div.detailVelikost").addClass("opacityHalf");
            velikostText.removeClass("opacityHalf");                        
            $("div.detail").attr("velikost",velikost);
            getSklad();
        });
    });
    //kosik fademenu click
    function getBarvaDetailImg(barva){
        $("div.detail_obrazky").html('<img src="templates/eshop/imgs/LoadingIcon-White.gif" />').load("eshopScript/Ajax.php?barvaName="+barva,function(){
            getZoom();
            createMiniMenu();
        });
    }
    
    //search
    $("#search").keyup(function(){
        var search = $(this).val();
        search = search.trim();
        search = search.replace(" ","+");
        search = search.replace(" ","+");
        search = search.replace(" ","+");
        search = search.replace(" ","+");
        search = search.replace(" ","+");
        if (search.length > 2){
            $("div.itemListDiv").html('<img src="templates/eshop/imgs/LoadingIcon-Gray.gif" />').load("eshopScript/Ajax.php?search="+search);
        }
    });
    //search
    //pridat do kosiku
    $("#pridatDoKosiku").live("click",function(event){
        pridatZbozi();
    });
    function pridatZbozi(){
        var barva = $("div.detail").attr("barva");
        var velikost = $("div.detail").attr("velikost");
        var amount = 1;
        var itemId = $("div.detail").attr("detailitemid");
        var validation = true;
        if (barva == null){
            $.get("eshopScript/Ajax.php",{
                ajax : "color"
            }, function(data){
                alert( data);
            });            
            validation = false;
        }
        if (velikost == null && validation){
            $.get("eshopScript/Ajax.php",{
                ajax : "size"
            }, function(data){
                alert( data);
            }); 
            validation = false;
        }
        if (amount =="" && validation){
            $.get("eshopScript/Ajax.php",{
                ajax : "amount"
            }, function(data){
                alert( data);
            }); 
            validation = false;
        }                    
        if (validation){
            $("#blind").load("eshopScript/Ajax.php?addItemToCart=&barva="+barva+"&velikost="+velikost+"&amount="+amount+"&itemId="+itemId,function(){
                refreshCart();
                refreshUser();                
            });            
            return validation;
        }else{
            return validation;
        }
    }
    refreshCart();
    function refreshCart(){
        $("div.kosikMouseMenu").html('<img src="templates/eshop/imgs/LoadingIcon-White.gif" />').load("eshopScript/Ajax.php?cart="); 
        $("div.kosikMouseOverIN").load("eshopScript/Ajax.php?kosik=", function(){
            $("#numberOfItemsInCart").animate({
                fontSize: "24px"
            }, "slow").animate({
                fontSize:"13px"
            },"slow");
        });
                    
    }
    //pridat do kosiku
    //velikost click
    $("div.detailVelikost").live("click",function(){
        $("div.detailVelikost").addClass("opacityHalf");
        $(this).removeClass("opacityHalf");
        var velikost = $(this).attr("velikost");
        $("div.detail").attr("velikost",velikost);
        getSklad();
    });
    //velikost click
    //barva click
    $("img.detailBarva").live("click",function(){
        $("img.detailBarva").addClass("opacityHalf");
        $(this).removeClass("opacityHalf");
        var barva = $(this).attr("barva");
        $("div.detail").attr("barva",barva);              
        $("div.detail_obrazky").html('<img src="templates/eshop/imgs/LoadingIcon-White.gif" />').load("eshopScript/Ajax.php?barvaName="+barva,function(){
            getZoom();
            createMiniMenu();
        });
        getSklad();
    });
    
    function getPrvniBarva(){
        var vyberBarvyObjekt =$("img.detailBarva:first");
        var barva = vyberBarvyObjekt.attr("barva");
        $("img.detailBarva").addClass("opacityHalf");
        vyberBarvyObjekt.removeClass("opacityHalf");
        $("div.detail").attr("barva",barva);
        $("div.detail_obrazky").html('<img src="templates/eshop/imgs/LoadingIcon-White.gif" />').load("eshopScript/Ajax.php?barvaName="+barva,function(){
            getZoom();
            createMiniMenu();
        });
        getSklad();
    }
    //barva click
    //addimagetobarva
    $("div.addImageToColor").live("click",function(){                    
        var id = $(this).attr("id_addimagetocolour");        
        $("#blind").load("eshopScript/AdminAjax.php?addImageToColor=&id_addimagetocolour="+id,function(){
            $("div.detail_obrazky").html('<img src="templates/eshop/imgs/LoadingIcon-White.gif" />').load("eshopScript/Ajax.php?barvaName="+id,function(){
                getZoom();
                createMiniMenu();
            });                    
        });
    });
    //addimagetobarva
    var lastSklad = null;
    function getSklad(){
        var barva = $("div.detail").attr("barva");
        var velikost = $("div.detail").attr("velikost");
        var itemId = $("div.detail").attr("detailitemid");
        if (velikost != null && barva != null && itemId != null){
            if (lastSklad == null){
                $("#sklad_"+barva+"_"+velikost).show();
                lastSklad = $("#sklad_"+barva+"_"+velikost);
            }else{
                lastSklad.hide();
                $("#sklad_"+barva+"_"+velikost).show();                            
                lastSklad = $("#sklad_"+barva+"_"+velikost);
            }
        }
    }
    //fademenuclick    
    var readyToRefresh = false;
    $("div.kosik_refresh").live("click",function(event){
        readyToRefresh = false;    
        refresh_kosikOverview(null);        
    });
    var refreshInterval = null;
    function refresh_kosikOverview(){    
        if (refreshInterval == null) {
            refreshInterval = setInterval(refresh_kosikOverview,100);     
        }
        if (readyToRefresh){            
            location.hash = "k"; 
            clearInterval(refreshInterval);
            refreshInterval = null;
        }
    }
    
    $("div.kosik_odstranit").live("click",function(event){
        var barva = $(this).attr("barva");
        var velikost = $(this).attr("velikost");
        var amount = $(this).attr("amount");
        var itemId = $(this).attr("odstranit_itemId");
        $("#blind").load("eshopScript/Ajax.php?removeItemFromCart=&barva="+barva+"&velikost="+velikost+"&amount="+amount+"&itemId="+itemId, function(){
            refreshCart();
            readyToRefresh = true;
        });                    
    });
    $("div.kosikMouseOver").click(function(event){
        var loged = $("div.loged").attr("loged");
        if (loged){
            location.hash = "k";                    
        }else{
            $(window.location).attr('href', 'index.php?action=eshop/register');
        }
    });
    $("div.logout").click(function(event){
        var loged = $("div.loged").attr("loged");
        if (loged){
            $(window.location).attr('href', 'eshopScript/LoginRegisterResolution.php?logout=');
        }else{
                        
    }
    });
    $("div.admin_addItem").click(function(event){
        $(window.location).attr('href', 'index.php?action=eshop/addItem');
    });
    $("div.historie").click(function(event){
        $("div.itemListDiv").html('<img src="templates/eshop/imgs/LoadingIcon-Gray.gif" />').load("eshopScript/Ajax.php?orderList=");
    });
    $("div.kontaktniUdaje").click(function(event){
        $("div.itemListDiv").html('<img src="templates/eshop/imgs/LoadingIcon-Gray.gif" />').load("eshopScript/Ajax.php?kontaktniUdajeZmena=");
    });
    $("div.sprava_objednavek").click(function(event){
        $("div.itemListDiv").html('<img src="templates/eshop/imgs/LoadingIcon-Gray.gif" />').load("eshopScript/AdminAjax.php?orderList=");
    });
    $("div.admin_sekce").click(function(event){
        $(window.location).attr('href', 'index.php?action=eshop/sectionEdit');
    });
    //fademenuclick
    //fademenu
    $("div.adminMouseMenu").hover(function(event){
                    
        },function(event){
            $(this).stop(true, true).fadeOut(300);
        });
    $("div.kosikMouseMenu").hover(function(event){
                    
        },function(event){
            $(this).stop(true, true).fadeOut(300);
        });
    $("div.kosikMouseOver").hover(function(event){
        var loged = $("div.loged").attr("loged");
        if (loged == "admin"){
            $("div.adminMouseMenu").stop(true, true).fadeIn(300);
            $("div.userMouseMenu").stop(true, true).fadeOut(300);   
        }
        if (loged == "user"){
            $("div.kosikMouseMenu").stop(true, true).fadeIn(300);
            $("div.userMouseMenu").stop(true, true).fadeOut(300);                        
        }
    },function(event){
                                      
        });
    $("div.userMouseMenu").hover(function(event){
                    
        },function(event){
            $(this).fadeOut(300);
        });
                
    $("div.userMouseOver").hover(function(event){
        var loged = $("div.loged").attr("loged");
        if (loged){            
            $("div.userMouseMenu").stop(true, true).fadeIn(300);
            $("div.kosikMouseMenu").stop(true, true).fadeOut(300);
            $("div.adminMouseMenu").stop(true, true).fadeOut(300);
        }else{
                        
    }
    },function(event){         
        });
    $("div.topDiv").hover(function(event){
        
        }, function(event){
            var isItOk = false;
            if (event.pageX <=$(this).offset().left){
                isItOk = true;
            }
            if (event.pageX >=($(this).offset().left+$(this).width())){
                isItOk = true;
            }
            if (event.pageY <=$(this).offset().top){
                isItOk = true;
            }
            if (event.pageY >=($(this).offset().top+$(this).height())){
                isItOk = true;
            }            
            if (isItOk){
                $("div.kosikMouseMenu").stop(true, true).fadeOut(300);
                $("div.adminMouseMenu").stop(true, true).fadeOut(300);
                $("div.userMouseMenu").stop(true, true).fadeOut(300);     
            }
        });                
    //fademenu
    //menu siblings("div.tag").attr("style") == "display: none;"
    $("a.tag").click(function(event){
        if ($(this).attr("section") == location.hash.replace("#", "")){
            location.hash = "s"+$(this).attr("section");
        }else{
            location.hash = $(this).attr("section");
        }
    });
    //menu
    //changepage
    $("div.changePage").live("click",function(event){
        location.hash = "changePage="+$(this).attr("link");
    //$("div.itemListDiv").html('<img src="templates/eshop/imgs/LoadingIcon-Gray.gif" />').load($(this).attr("link"));                         
    });
    //changepage                
    //itemdetail
    $("div[itemId]").live("click",function(event){
        location.hash = "i"+$(this).attr("itemId");        
    });
                
    function loadDetail(itemId){                    
        $("div.itemListDiv").html('<img src="templates/eshop/imgs/LoadingIcon-Gray.gif" />').load("eshopScript/Ajax.php?detailItemId="+itemId,function(event){
            getPrvniBarva();
            createMiniMenu();
        });        
    }
    function updatePage(updateParam){
        $("div.itemListDiv").html('<img src="templates/eshop/imgs/LoadingIcon-Gray.gif" />').load("eshopScript/Ajax.php?updateParam="+updateParam,function(event){            
            createMiniMenu();
        }); 
    }
    $("div.superlink").live("click",function(event){
        if ($(this).attr("data-targetelement") == "parent"){
            $(this).parent().html('<img src="templates/eshop/imgs/LoadingIcon-Gray.gif" />').load($(this).attr("data-target"),function(event){            
                createMiniMenu();
            }); 
        }
        if ($(this).attr("data-targetElement") == ""){
            ("div.itemListDiv").html('<img src="templates/eshop/imgs/LoadingIcon-Gray.gif" />').load($(this).attr("data-target"),function(event){            
                createMiniMenu();
            }); 
        }else{
            $("#"+$(this).attr("data-targetelement")).html('<img src="templates/eshop/imgs/LoadingIcon-Gray.gif" />').load($(this).attr("data-target"),function(event){            
                createMiniMenu();
            }); 
        }
    });   
    //itemdetail
    $("#listOfSections").html('<img src="templates/eshop/imgs/LoadingIcon-Gray.gif" />').load("eshopScript/Ajax.php?sectionList=");
    $("#listOfSectionsFull").html('<img src="templates/eshop/imgs/LoadingIcon-Gray.gif" />').load("eshopScript/Ajax.php?sectionListFull=");
    $("#velikosti").html('<img src="templates/eshop/imgs/LoadingIcon-Gray.gif" />').load("eshopScript/Ajax.php?sizeList=");
    $("#barvy").html('<img src="templates/eshop/imgs/LoadingIcon-Gray.gif" />').load("eshopScript/Ajax.php?colorList=");
    $("div.kosikMouseOverIN").html('<img src="templates/eshop/imgs/LoadingIcon-White.gif" />').load("eshopScript/Ajax.php?kosik=");
    $("div.userMouseOverIN").html('<img src="templates/eshop/imgs/LoadingIcon-White.gif" />').load("eshopScript/Ajax.php?user=");
    
    function refreshUser(){
        $("div.userMouseOverIN").html('<img src="templates/eshop/imgs/LoadingIcon-White.gif" />').load("eshopScript/Ajax.php?user=");
    }
                
            
    $("input.colorbox").live("click",function(event){
        var idval = $(this).attr("barva");
        var divClass = "file_"+idval;
        var div = $("div."+divClass);
        //var count = $(this).attr("count");
        if ($(this).attr("checked")){
            div.show();
            div.append('<input type="file" name="img0_'+idval+'" /><br/>');
            div.append('<input type="file" name="img1_'+idval+'" /><br/>');
            div.append('<input type="file" name="img2_'+idval+'" /><br/>');
            div.append('<input type="file" name="img3_'+idval+'" /><br/>');
            $(this).attr("count",4);
        }else{
            $(this).attr("count",0);
            div.empty();
            div.hide();
        }
    });
    $("img.subImage.pointer").live("mouseenter",function(){
        $("img.mainImage").attr("src",$(this).attr("mainImageSrc"));
        $("a.mainImageFull").attr("href",$(this).attr("mainImageFull"));
        getZoom();
    });
    
    //modal window                
    $('a[name=modal]').live("click",function(e) {                    
        e.preventDefault();
                    
        var id = "#"+$(this).attr('href');
                    
        var maskHeight = $(document).height();
        var maskWidth = $(window).width();
                    
        $('#mask').css({
            'width':maskWidth,
            'height':maskHeight
        });
                    
        $('#mask').fadeTo("fast",0.85); 
                    
        var winH = $(window).height();
        var winW = $(window).width();
               
     
        $(id).css('top',  winH/2-$(id).height()/2);
        $(id).css('left', winW/2-$(id).width()/2);
                    
        $(id).fadeIn(500);
                    
        var type = $(id).attr("type");
        if (type == "velikosti"){
            $("div."+$(this).attr('href')).html('<img src="templates/eshop/imgs/LoadingIcon-White.gif" />').load("eshopScript/AdminAjax.php?velikosti=&idmap="+$(this).attr('href'));
        }
        if (type == "barvy"){
            $("div."+$(this).attr('href')).html('<img src="templates/eshop/imgs/LoadingIcon-White.gif" />').load("eshopScript/AdminAjax.php?barvy=&idmap="+$(this).attr('href'));
        }
        if (type == "image"){
            if ($("#file-uploader_"+$(this).attr('href')).attr("data-type") != null){  
                if ($("#file-uploader_"+$(this).attr('href')).attr("data-type") == "insertImage"){
                    var href = $(this).attr('href');                    
                    var uploader = new qq.FileUploader({
                        element: document.getElementById('file-uploader_'+$(this).attr('href')),                
                        action: 'eshopScript/FileUpload.php',
                        params: {
                            id: $("#file-uploader_"+$(this).attr('href')).attr("data-type")                              
                        },    
                        onComplete: function(id, filename, responseJSON) {
                            if (responseJSON.success) {                                
                                $.post("eshopScript/AdminAjax.php", {
                                    getLastImage: true
                                }, function(data) {     
                                    current = $("#"+href+"_ckeditor").val();
                                    $("#"+href+"_ckeditor").val(current+'<img src="'+data+'" alt="image"/>');
                                });
                            }
                        }
                    });                                         
                }else{
                    var uploader = new qq.FileUploader({
                        element: document.getElementById('file-uploader_'+$(this).attr('href')),                
                        action: 'eshopScript/FileUpload.php',
                        params: {
                            id: $("#file-uploader_"+$(this).attr('href')).attr("data-type")                              
                        }                            
                    }); 
                }
            }else{
                var uploader = new qq.FileUploader({
                    element: document.getElementById('file-uploader_'+$(this).attr('href')),                
                    action: 'eshopScript/FileUpload.php',
                    params: {
                        id: $(this).attr('href')                                
                    }                            
                });   
            }
        }
                    
        if (type == "section"){
            $("#listOfSections").html('<img src="templates/eshop/imgs/LoadingIcon-White.gif" />').load("eshopScript/Ajax.php?sectionList=");
        }                    
        if (type == "editSection"){
            $("select."+$(this).attr('href')).html('<img src="templates/eshop/imgs/LoadingIcon-White.gif" />').load("eshopScript/Ajax.php?sectionListFull="+$(this).attr("data-parent"));
        }
    });
     
    $('.window .close').live("click",function (e) {
        //Cancel the link behavior
        e.preventDefault();
        $('#mask, .window').hide();
    });    
     
    $('#mask').live("click",function () {
        $(this).hide();
        $('.window').hide();
    }); 
    //editConfirm
    $("span.editTextConfirm").live("click",function (e){
        var id = $(this).attr("name");
        var text = $("textarea."+id).val();
        $.post("eshopScript/AdminAjax.php", {
            data: text, 
            name: id, 
            updateText: "true"
        }, function(data) {
            if ($("div.detail").attr("detailitemid") != null){
                loadDetail($("div.detail").attr("detailitemid"));
            }else{
                $(window.location).attr('href', 'index.php?action=eshop/success');
            }
        });
        $('#mask, .window').hide();        
    });                
    $("span.editIntConfirm").live("click",function (e){
        var id = $(this).attr("name");
        var text = $("input."+id).val();
        $.post("eshopScript/AdminAjax.php", {
            data: text, 
            name: id, 
            updateInt: "true"
        }, function(data) {
            if ($("div.detail").attr("detailitemid") != null){
                loadDetail($("div.detail").attr("detailitemid"));
            }else{
                $(window.location).attr('href', 'index.php?action=eshop/success');
            }
        });
        $('#mask, .window').hide();
    });   
    $("span.editDynConfirm").live("click",function (e){
        var id = $(this).attr("name");
        var text = $("form."+id).serialize();
        $.post("eshopScript/AdminAjax.php", text, function(data) {
            if ($("div.detail").attr("detailitemid") != null){
                loadDetail($("div.detail").attr("detailitemid"));
            }else{
                $(window.location).attr('href', 'index.php?action=eshop/success');
            }
        });
        $('#mask, .window').hide();
    }); 
    $("span.editImgConfirm").live("click",function (e){        
        location.reload(true);
    }); 
    $("span.editConfirm").live("click",function (e){
        var id = $(this).attr("name");
        var text = $("form."+id).serialize();
        $.post("eshopScript/AdminAjax.php", text, function(data) {
            if ($("div.detail").attr("detailitemid") != null){
                if (id.indexOf("delete") > -1 ){
                    $(window.location).attr('href', 'index.php?action=eshop/success');
                }else{
                    loadDetail($("div.detail").attr("detailitemid"));
                }                
            }else{
                $(window.location).attr('href', 'index.php?action=eshop/success');
            }
        });
        $('#mask, .window').hide();                    
    }); 
    //modal window    
    //msg
    if ($("#msg").html() != ""){
        alert($("#msg").html());
    }
    //msg
    //editLinkVisibility
    function createMiniMenu(){    
        $("div.minimenu").each(function(){    
            var a = $(this);             
            var type = a.attr("data-type");
            var parent = a.parent().attr("id");
            var divCat;
            if (type == "always-visible"){
                if ($("#minimenuDiv_"+parent).html() == null){
                    var parentElement = $("#"+parent);
                    parentElement.addClass("inline-table");
                    parentElement.append('<div id="minimenuDiv_'+parent+'" class="minimenuCatPositionAlwaysVisible floatRight"></div>');            
                    divCat = $("#minimenuDiv_"+parent);                                       
                }else{
                    divCat = $("#minimenuDiv_"+parent);
                }                    
                var ahtml = a.html();
                a.remove();
                divCat.append(ahtml); 
            }else{
                if ($("#minimenuDiv_"+parent).html() == null){
                    var parentElement = $("#"+parent);
                    if (parentElement.attr("data-type") == "noinline"){
                        
                    }else{
                        parentElement.addClass("inline-table");
                    }
                    parentElement.append('<div id="minimenuDiv_'+parent+'" class="hidden minimenuCatPosition floatRight fixedPos"></div>');            
                    divCat = $("#minimenuDiv_"+parent);                    
                    parentElement.die("mouseenter",miniMenuMouseEnter);
                    parentElement.live("mouseenter",{
                        divCat : divCat , 
                        parent : parentElement
                    },miniMenuMouseEnter);
                    divCat.die("hover",miniMenuHover);
                    divCat.live("hover",{
                        divCat : divCat
                    },miniMenuHover);
                    divCat.die("mouseleave",miniMenuMouseOut);
                    divCat.live("mouseleave",{
                        divCat : divCat
                    },miniMenuMouseOut);
                }else{
                    divCat = $("#minimenuDiv_"+parent);
                }                    
                var ahtml = a.html();
                a.remove();
                divCat.append(ahtml);                                    
            }
        });
    }
    function miniMenuHover(e){
        var divCat = e.data.divCat;          
        divCat.stop(true,true).show();  
    }
    function miniMenuMouseOut(e){
        var divCat = e.data.divCat;
    //divCat.stop(true,true).fadeOut(3000);
    }
    function miniMenuMouseEnter(e){
        var divCat = e.data.divCat;                
        var parent = e.data.parent;                
        var x = e.clientX;
        var y = e.clientY;
        if (divCat.is(":hidden") == true ){  
            if (visibleEditElement != null){
                visibleEditElement.attr("style","display:block;");
            }
            $("div.minimenuCatPosition").stop(true,true).hide();
            divCat.stop(true,true).show();            
            visibleEditElement=divCat;
            correctMinimenuPosition();
        //divCat.css({left: x, top: y});
        //divCat.fadeOut(3000);
        }
        
    }
    //editLinkVisibility
    $(window).hashchange( function(){
        var hash = location.hash.replace("#","");
        while (true){
            if (hash.indexOf("prejitKPokladne") > -1){
                location.hash = "done"+ (new Date()).getTime();
                updatePage("prejitKPokladne");
                break;
            }
            if (hash.indexOf("sendForm:") > -1){
                hash = hash.replace("sendForm:","");
                sendForm(hash);
                location.hash = "done"+ (new Date()).getTime();    
                refreshCart();
                refreshUser();
                break;
            }
            if (hash.indexOf("changePage=") > -1){
                hash = hash.replace("changePage=","");
                $("div.itemListDiv").html('<img src="templates/eshop/imgs/LoadingIcon-Gray.gif" />').load(hash)
                break;
            }
            if (hash.indexOf("i") > -1){
                loadDetail(hash.replace("i",""));
                break;
            }
            
            if (hash.indexOf("s") > -1){
                $('a.tag[section='+hash.replace("s","")+']').each(function(){
                    var that = $(this);
                    aTagClick(that);            
                });
                break;
            }    
            if (hash.indexOf("k") > -1){
                location.hash = "done"+ (new Date()).getTime();
                updatePage("kosik");
                break;
            }
            $('a.tag[section='+hash+']').each(function(){
                var that = $(this);
                aTagClick(that);            
            });
            break;
        }
    })

    function aTagClick(that){        
        var thatDiv = that.parent();
        if (that.attr("wtf") != 0) {
            thatDiv.siblings("div.tag").stop(true, true).show("slow");
            that.siblings("span.fontBold").text("-");
            that.attr("wtf","0");
        }else{
            thatDiv.siblings("div.tag").stop(true, true).hide("slow");
            that.siblings("span.fontBold").text("+");
            that.attr("wtf","1");
        }
        if (lastMenuObject != null){
            lastMenuObject.addClass("underline");
            lastMenuObject.removeClass("bold");
            lastMenuObject.parent().siblings(".arrow").stop(true, true).hide();
        }
        var typeId = that.attr("section");
        that.removeClass("underline");
        that.addClass("bold");
        thatDiv.siblings(".arrow").stop(true, true).show();
        while(true){
            if (that.attr("section") == 27){
                $("div.itemListDiv").html('<img src="templates/eshop/imgs/LoadingIcon-Gray.gif" />').load("eshopScript/Ajax.php?updateParam=vyhledavaniVelikosti",function(event){            
                    createMiniMenu();
                    $("#velikosti").html('<img src="templates/eshop/imgs/LoadingIcon-Gray.gif" />').load("eshopScript/Ajax.php?sizeList=");
                }); 
                break;   
            }
            if (that.attr("section") == 23){
                updatePage("kontakt");
                break;   
            }
            if (that.attr("section") == 22){
                updatePage("tabulkaVelikosti");
                break;   
            }
            if (that.attr("section") == 25){
                updatePage("infoZnac");
                break;   
            }
            $("div.itemListDiv").html('<img src="templates/eshop/imgs/LoadingIcon-Gray.gif" />').load("eshopScript/Ajax.php?section="+typeId);                    
            break;
        }
        lastMenuObject = that; 
    }    
    
    $(window).hashchange();
    createMiniMenu();
    
    //admin
    $("div.obednavkaHeaderDiv").live("mouseover",function (event) {        
        $(this).addClass("orderListHover");        
    });
    $("div.obednavkaHeaderDiv").live("mouseout",function (event) {        
        $(this).removeClass("orderListHover");        
    });
    $("div.obednavkaHeaderDiv").live("click",function(event){   
        if ($(this).hasClass("superlink")){
            $(this).removeClass("orderListClick");            
        }else{
            if ($(this).hasClass("orderListClick")){
                $(this).removeClass("orderListClick");
                $(this).find(".obednavkaUserBox").hide("fast");            
                $(this).find(".obednavkaDorucBox").hide("fast");            
                $(this).find(".obednavkaZboziBox").hide("fast"); 
            }else{
                $(this).addClass("orderListClick");
                $(this).find(".obednavkaUserBox").show("fast");    
                $(this).find(".obednavkaDorucBox").show("fast");      
                $(this).find(".obednavkaZboziBox").show("fast");            
            }        
        }
    });
    
    //vyhledání podle velikostí
    $(".findBySizeBox > div").live("click",function(event){
        id = $(this).text();        
        var selected = $(this).find("input");
        $(".findBySizeResult").load("eshopScript/Ajax.php?searchBySize="+id.trim());
        $(".findBySizeBox").find("input").each(function(){
            if ($(this)[0] != selected[0]){
                $(this).attr('checked', false);
            }
        })
    })
});




//numberValidation
function isNumberKey(evt)
{
    var charCode = (evt.which) ? evt.which : event.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57))
        return false;

    return true;
}
//numberValidation
//send form id
function sendForm(id){
    var text = $("#"+id).serialize();
    $.post("eshopScript/Ajax.php?form=true", text, function(data) {
        //callback
        if ($("div.detail").attr("detailitemid") != null){
            loadDetail($("div.detail").attr("detailitemid"));
        }else{
            if (data != null){
                $("div.itemListDiv").html(data);
            }else{
                $(window.location).attr('href', 'index.php?action=eshop/success');
            }            
        }
    });
}


